3 Version 2 (29th May 2004)
\r
5 use short duration bars e.g.
\r
6 5min set length to give required speed of response
\r
7 increase damping to eliminate overshooting
\r
8 Lower length will require Higher damping
\r
11 Äëÿ ðàáîòû èíäèêàòîðà ñëåäóåò ïîëîæèòü ôàéëû
\r
12 INDICATOR_COUNTED.mqh
\r
14 â ïàïêó (äèðåêòîðèþ): MetaTrader\experts\include\
\r
16 â ïàïêó (äèðåêòîðèþ): MetaTrader\indicators\
\r
18 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
\r
19 //| JMorris MA.mq4 |
\r
20 //| Copyright © 2003,2004 Tim Morris |
\r
22 //| MQL4 © 2005, Nikolay Kositsin |
\r
23 //| Khabarovsk, farria@mail.redcom.ru |
\r
24 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
\r
25 #property copyright "Nikolay Kositsin"
\r
26 #property link "farria@mail.redcom.ru"
\r
27 //---- îòðèñîâêà èíäèêàòîðà â ãëàâíîì îêíå
\r
28 #property indicator_chart_window
\r
29 //---- êîëè÷åñòâî èíäèêàòîðíûõ áóôôåðîâ
\r
30 #property indicator_buffers 1
\r
31 #property indicator_color1 Red
\r
32 //---- ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþææ+
\r
33 extern int Length = 10;//inverse of driving coefficient
\r
34 extern int damping = 5;//smoothing (percent)
\r
35 extern int maxgap = 30;//maximum week gap ignored (pips)
\r
36 extern int Smooth = 8; // ãëóáèíà ñãëàæèâàíèÿ
\r
37 extern int Smooth_Phase = 100;// ïàðàìåòð ñãëàæèâàíèÿ, èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
\r
38 extern int Shift = 0;
\r
39 extern int Input_Price_Customs = 2; //Âûáîð öåí, ïî êîòîðûì ïðîèçâîäèòñÿ ðàñ÷¸ò èíäèêàòîðà
\r
40 //(0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL, 6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW,
\r
41 //11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open, 14-Heiken Ashi Close.)
\r
42 //---- æææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ+
\r
43 //---- èíäèêàòîðíûå áóôôåðû
\r
44 double MMA_Buffer [];
\r
46 //---- ïåðåìåííûå ñ ïëàâàþùåé òî÷êîé
\r
47 double p, dmp, drv, gap;
\r
48 double n, k, d0, y0, y1, y2, mg, err, Resalt;
\r
49 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
\r
50 //| Morris MA initialization function |
\r
51 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
\r
54 //---- îïðåäåëåíèå ñòèëÿ èñïîëíåíèÿ ãðàôèêà
\r
55 SetIndexStyle (0,DRAW_LINE);
\r
56 //---- 2 èíäèêàòîðíûõ áóôôåðà èñïîëüçîâàíû äëÿ ñ÷¸òà.
\r
57 IndicatorBuffers(2);
\r
58 SetIndexBuffer(0, MMA_Buffer);
\r
59 SetIndexBuffer(1, MEMORY);
\r
60 //---- ãîðèçîíòàëüíûé ñäâèã èíäèêàòîðíîé ëèíèè
\r
61 SetIndexShift (0, Shift);
\r
62 //---- èìÿ äëÿ îêîí äàííûõ è ëýéáà äëÿ ñóáúîêîí.
\r
63 SetIndexLabel (0, "Moris_MA");
\r
64 IndicatorShortName ("Moris_MA (Length="+Length+", damping="+damping+", maxgap="+maxgap+", Shift="+Shift+")");
\r
66 k =1.0/Length; d0 = damping/100.0; mg = maxgap*Point;
\r
68 IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
\r
69 //---- óñòàíîâêà àëåðòîâ íà íåäîïóñòèìûå çíà÷åíèÿ âõîäíûõ ïàðàìåòðîâ ======================================================================================+
\r
70 if(Smooth_Phase<-100){Alert("Ïàðàìåòð Smooth_Phase äîëæåí áûòü îò -100 äî +100" + " Âû ââåëè íåäîïóñòèìîå " +Smooth_Phase+ " áóäåò èñïîëüçîâàíî -100");}//|
\r
71 if(Smooth_Phase> 100){Alert("Ïàðàìåòð Smooth_Phase äîëæåí áûòü îò -100 äî +100" + " Âû ââåëè íåäîïóñòèìîå " +Smooth_Phase+ " áóäåò èñïîëüçîâàíî 100");}//|
\r
72 if(Smooth< 1) {Alert("Ïàðàìåòð Smooth äîëæåí áûòü íå ìåíåå 1" + " Âû ââåëè íåäîïóñòèìîå " +Smooth+ " áóäåò èñïîëüçîâàíî 1");}//////////////////|
\r
73 if(Length<1) {Alert("Ïàðàìåòð Length äîëæåí áûòü íå ìåíåå 1 "+ " Âû ââåëè íåäîïóñòèìîå " +Length+ " áóäåò èñïîëüçîâàíî 1");}//////////////////////|
\r
74 PriceSeriesAlert(Input_Price_Customs);/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////|
\r
75 //+========================================================================================================================================================+
\r
76 //---- êîðåêöèÿ íåäîïóñòèìîãî çíà÷åíèÿ ïàðàìåòðà Bands_Period
\r
77 if(Length<1)Length=1;
\r
78 //---- çàâåðøåíèå èíèöèàëèçàöèè
\r
81 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
\r
82 //| Morris MA iteration function |
\r
83 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
\r
86 //----+ Ââåäåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîäñ÷èòàííûõ áàðîâ
\r
87 //---- áëîêèðîâàíèå ïåðåñ÷¸òà âñåõ ïîäñ÷èòàííûõ è îòðèñîâàííûõ áàðîâ ïðè ïîäêëþ÷åíèè ê èíòåðíåòó
\r
88 int MaxBar,reset,bar,limit,counted_bars=INDICATOR_COUNTED(0); INDICATOR_COUNTED(1);
\r
89 //---- ïðîâåðêà íà âîçìîæíûå îøèáêè
\r
90 if (counted_bars<0){INDICATOR_COUNTED(-1);return(-1);}
\r
91 //---- ïîñëåäíèé ïîäñ÷èòàííûé áàð äîëæåí áûòü ïåðåñ÷èòàí
\r
92 if (counted_bars>0) counted_bars--;
\r
93 //----+ Ââåäåíèå è èíèöèàëèçàöèÿ âíóòðåííèõ ïåðåìåííûõ ôóíêöèè JJMASeries, nJMAnumber=1(Îäíî îáðàùåíèå ê ôóíêöèè)
\r
94 if (counted_bars==0)JJMASeriesReset(1);
\r
95 //---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà, íà÷èíàÿ ñ êîòîðîãî áóäåò ïðîèçåä¸í ïåðåñ÷¸ò íîâûõ áàðîâ
\r
96 limit=Bars-counted_bars-1;MaxBar=Bars-1-2;
\r
101 y0=PriceSeries(Input_Price_Customs,MaxBar);
\r
103 MEMORY[MaxBar+0]=y0;
\r
104 MEMORY[MaxBar+1]=y0;
\r
105 MEMORY[MaxBar+2]=y0;
\r
107 MMA_Buffer[MaxBar+0]=y0;
\r
108 MMA_Buffer[MaxBar+1]=0.0;
\r
109 MMA_Buffer[MaxBar+2]=0.0;
\r
114 p=PriceSeries(Input_Price_Customs,bar);
\r
115 //week} gap compensation------------------------------------------+
\r
116 if (Time[bar]-Time[bar+1]>30000)
\r
117 if ((High[bar]<Low[bar+1])||(Low[bar]>High[bar+1]))
\r
119 gap=p-PriceSeries(Input_Price_Customs,bar+1);
\r
120 if (MathAbs(gap)>mg){MEMORY[bar+1]+=gap; MEMORY[bar+2]+=gap;}
\r
122 //----------------------------------------------------------------+
\r
123 //*** calculate new average position ***
\r
124 y1 = MEMORY[bar+1];
\r
125 y2 = MEMORY[bar+2];
\r
126 n = High[bar]-Low[bar];//consider H-L as noise level
\r
127 if(n==0)n=Point/100;
\r
128 err = (p-2.0*y1+y2)/n;
\r
129 //error is difference between price && straight line
\r
130 drv = MathMax(MathMin(k*err*err + k*MathAbs(err),0.5),0.0);
\r
131 //driving function = polynomial of error/noise
\r
132 //small moves have little effect,
\r
133 //big moves have big effect,
\r
134 //spikes have small effect
\r
135 dmp = MathMax(MathMin(k*MathAbs(y1-y2)/n + d0,1.0),0.0);
\r
136 //damping function = polynomial of gradient/noise
\r
137 //if average is moving fast but price isn't - put the brakes on.
\r
138 y0 = y1 + n*err*drv + (y1-y2)*(1.0-dmp);
\r
139 //new average = straight line less damping plus driving
\r
141 //----+ Îáðàùåíèå ê ôóíêöèè JJMASeries çà íîìåðàì 0. Ïàðàìåòðû nJMAPhase è nJMALength íå ìåíÿþòñÿ íà êàæäîì áàðå (nJMAdin=0)
\r
142 Resalt=JJMASeries(0,0,MaxBar,limit,Smooth_Phase,Smooth,y0,bar,reset);
\r
143 //----+ ïðîâåðêà íà îòñóòñòâèå îøèáêè â ïðåäûäóùåé îïåðàöèè
\r
144 if(reset!=0){INDICATOR_COUNTED(-1);return(-1);}
\r
145 MMA_Buffer[bar]=Resalt;
\r
151 //+---------------------------------------------------------------------------------------------------------------------------+
\r
152 //----+ Ââåäåíèå ôóíêöèè JJMASeries (ôàéë JJMASeries.mqh ñëåäóåò ïîëîæèòü â ïàïêó (äèðåêòîðèþ): MetaTrader\experts\include)
\r
153 //----+ Ââåäåíèå ôóíêöèè JJMASeriesReset (äîïîëíèòåëüíàÿ ôóíêöèÿ ôàéëà JJMASeries.mqh)
\r
154 //----+ Ââåäåíèå ôóíêöèè INDICATOR_COUNTED(äîïîëíèòåëüíàÿ ôóíêöèÿ ôàéëà JJMASeries.mqh)
\r
155 #include <JJMASeries.mqh>
\r
156 //+---------------------------------------------------------------------------------------------------------------------------+
\r
157 //----+ Ââåäåíèå ôóíêöèè PriceSeries, ôàéë PriceSeries.mqh ñëåäóåò ïîëîæèòü â ïàïêó (äèðåêòîðèþ): MetaTrader\experts\include
\r
158 //----+ Ââåäåíèå ôóíêöèè PriceSeriesAlert (äîïîëíèòåëüíàÿ ôóíêöèÿ ôàéëà PriceSeries.mqh)
\r
159 #include <PriceSeries.mqh>
\r
160 //+---------------------------------------------------------------------------------------------------------------------------+